﻿#light

module PubSim.Milk

open System
open Microsoft.FSharp.Control

/// Milk type definition ... used to set status of whether milk is on the cupboard
/// shelf or not.
type Milk(initValue) =
    let mutable milk = initValue
    let lockObj = new Object()

    member m.AddMilkToCupboard() =
        milk <- true
        ignore()
    member m.FetchMilkFromCupboard() =
        lock lockObj (fun() ->
            if milk = true then
                milk <- false
                true
            else
                false
        )
    member m.IsMilkInCupboard() =
        milk
